import jinja2
import os
import xlrd
from selenium import webdriver

from Base.BaseSetings import TestData_dir, Best_dir

class OpenBroswer():
    dr = None
    @classmethod
    def openbrower(cls):
        if cls.dr is None:
            cls.dr = webdriver.Firefox(executable_path=os.path.dirname(__file__)+"\\geckodriver.exe")
            cls.dr.maximize_window()
        else:
            pass
        return cls.dr


def readTable(tableObj):
    tbodyObj = tableObj.find_element_by_tag_name('tbody')
    trObjs = tbodyObj.find_elements_by_tag_name('tr')
    tableInfo = []
    for trObj in trObjs:
        tempList = []
        tdObjs = trObj.find_elements_by_tag_name('td')
        for tdObj in tdObjs:
            tempList.append(tdObj.text)
        tableInfo.append(tempList)
    return tableInfo

def read_excel():
    book = xlrd.open_workbook(TestData_dir+'woniuboss.xls')
    sheet = book.sheet_by_name('Sheet1')
    form_infos = sheet.get_rows_value()
    return form_infos

def render_tem(result):
    env = jinja2.Environment(
        loader=jinja2.FileSystemLoader(Best_dir),  # 模板的文件夹路径
        extensions=(),
        autoescape=True
    )
    # 通过loader传入的目录 找到目录下的  template_nam

    template = env.get_template("Template.html")
    print(result.case_detail_list)
    html = template.render(result=result)
    with open(Best_dir+ "\\Result.html", 'w', encoding="utf-8") as f:
        f.write(html)



if __name__ == '__main__':
    print(os.path.dirname(__file__))